package de.szut.ita13.rs.wave.entities;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import de.szut.ita13.rs.wave.controller.Controller;
import de.szut.ita13.rs.wave.entites.trail.Trail;
import de.szut.ita13.rs.wave.entity.Entity;
import de.szut.ita13.rs.wave.entity.Type;
import de.szut.ita13.rs.wave.hud.HUD;
import de.szut.ita13.rs.wave.main.Game;

public class Player extends Entity {
	

	private Controller controller;
	
	public Player(int x, int y, Type type, Controller controller) {
		super(x, y, type);
		this.controller = controller;
		this.color = type.getColor();
		this.width = type.getSize();
		this.height = type.getSize();
	}

	public void tick() {
		x += velocityX;
		y += velocityY;
		
		x = Game.clamp(x, 0, Game.WIDTH - 37);
		y = Game.clamp(y, 0, Game.HEIGHT - 60);
		
		controller.modificateEntity(new Trail(x, y, Type.Trail, color, width, height, 0.1f, controller), Controller.Modification.ADD);
		
		collision();
	}
	
	private void collision() {
		for(Entity entity : controller.entities) {
			if(entity.getType() == Type.BasicEnemy || entity.getType() == Type.FastEnemy) {
				if(getBounds().intersects(entity.getBounds())) {
					HUD.HEALTH -= entity.getDamage();
				}
			}
		}
	}

	public void render(Graphics g) {
		g.setColor(Color.WHITE);
		g.fillRect(x, y, width, height);
	}

	public Rectangle getBounds() {
		return new Rectangle(x, y, width, height);
	}

}
